#include <spi.h>
#include <stm32f10x.h>
#include <GPIO_config.h>

void SPI1_Init(void)
{
	RCC->APB2ENR |= 1<<12;
	GPIOA_Enable();
	GPIO_config(GPIOA,5,AF_PP);
	GPIO_config(GPIOA,6,PD_In);//这里和例程写的不一样，测试一下能不能这么写
	GPIO_config(GPIOA,7,AF_PP);

	SPI1->CR1 = 0x0000;//以防万一有别的函数没关使能
	SPI1->CR1 = 0x0337;
	SPI1->CR2 = 0;
	//使能SPI
	//SPI1->CR1 |= 1<<6;
}

//全双工模式下8bit DFF下，启动一帧传输
unsigned char SPI1_RW(unsigned char data)
{
	SPI1->CR1 |= 1<<6;//使能
	while((SPI1->SR & 0x0002) == 0);
	SPI1->DR = data;

	//等待RXNE == 1
	while((SPI1->SR & 0x0001) == 0);
	SPI1->CR1 &= ~(1<<6);
}

/*void SPI1_Stop(void)
{
	while()
}*/
